#include <atspi/atspi.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    // 初始化 AT-SPI
    if (atspi_init() != 0) {
        fprintf(stderr, "AT-SPI initialization failed\n");
        return 1;
    }
    
    printf("AT-SPI initialized successfully\n");
    
    // 获取桌面对象
    AtspiAccessible *desktop = atspi_get_desktop(0);
    if (!desktop) {
        fprintf(stderr, "Failed to get desktop object\n");
        atspi_exit();
        return 1;
    }
    
    printf("Desktop object obtained\n");
    
    // 获取桌面名称
    GError *error = NULL;
    const char *name = atspi_accessible_get_name(desktop, &error);
    if (error) {
        fprintf(stderr, "Error getting name: %s\n", error->message);
        g_error_free(error);
    } else {
        printf("Desktop name: %s\n", name ? name : "N/A");
    }
    
    // 获取桌面角色
    AtspiRole role = atspi_accessible_get_role(desktop, &error);
    if (error) {
        fprintf(stderr, "Error getting role: %s\n", error->message);
        g_error_free(error);
    } else {
        const char *role_name = atspi_role_get_name(role);
        printf("Desktop role: %s\n", role_name ? role_name : "Unknown");
    }
    
    // 清理资源
    g_object_unref(desktop);
    atspi_exit();
    
    printf("Program finished\n");
    return 0;
}